package com.example.day05.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;

@RestController
@RequestMapping("/api")
public class HelloController {

    @GetMapping("/hello")
    public Mono<String> sayHello() {
        return Mono.just("Hello, WebFlux!");
    }

    @GetMapping("/stream")
    public Flux<String> streamNumbers() {
        return Flux.interval(Duration.ofSeconds(1))
                .map(i -> "Number: " + i)
                .take(10);
    }

    @GetMapping("/user/{name}")
    public Mono<String> greetUser(@PathVariable String name) {
        return Mono.just("Hello, " + name + "!");
    }
}
